const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
    res.statusCode = 200;
    res.setHeader('Content-Type', 'text/plain');

    switch (req.url) {  //req.url:返回客户端请求的url地址
        case '/':
            res.end('helo world.');//http://127.0.0.1:3000/
            break;
        case '/about':
            res.end('This is about page.');//http://127.0.0.1:3000/about
            break;
        case '/home':
            res.end('Welcome to my homepage!');//http://127.0.0.1:3000/home
            break;
        default:
            res.end('NotFound!');//http://127.0.0.1:3000/任意
    }
});

server.listen(port, hostname, () => {
    console.log(`Server running at http://${hostname}:${port}/`);
});